from dataclasses import dataclass
import csv
from typing import List

@dataclass
class ClassLabel:
    name: str         # 类别名称，如 'chair'
    is_thing: bool = True    # 是否是独立物体（用于分割）
    size: str = 'S'        # 物体大小，'L' 'M' 'S'
    color: tuple = (0, 0, 0)     # 颜色 (R, G, B)

def get_class_labels(file_path: str) -> List[ClassLabel]:
    """
    从CSV文件中读取类别标签信息并返回ClassLabel对象列表。
    
    参数:
        file_path (str): CSV文件路径。
        
    返回:
        List[ClassLabel]: 类别标签对象列表。
    """
    class_labels = []

    with open(file_path, mode='r', newline='', encoding='utf-8') as csvfile:
        reader = csv.DictReader(csvfile)

        for row in reader:
            name = row['name']

            # 处理 r/g/b 字段缺失的情况，默认赋值为 0
            r = int(row.get('r', 0))
            g = int(row.get('g', 0))
            b = int(row.get('b', 0))
            color = (r, g, b)

            is_thing = bool(int(row.get('is_thing', 1)))
            size = row.get('size', 'S')

            class_label = ClassLabel(name=name, color=color, is_thing=is_thing, size=size)
            class_labels.append(class_label)

    return class_labels